home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBGRX100.ARJ / LIBGRX.DOC < prev    next >
Text File  |  1992-04-12  |  79KB  |  1,578 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.                                         LIBGRX
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.                       A 16/256 color graphics library for DJGPP
  26.  
  27.                                     User's Manual
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.                                      Written by:
  43.                                      Csaba Biegl
  44.  
  45.  
  46.                                     April 6, 1992
  47.  
  48.  
  49.  
  50.  
  51.  
  52.           LIBGRX graphics library user's manual                                 2
  53.  
  54.  
  55.           Abstract
  56.  
  57.                LIBGRX  is a graphics library for DJGPP or Turbo C programs.
  58.           (The Turbo C  version was  tested using TC++  1.01) Currently  it
  59.           supports  VGA (256  or  16 colors)  and  EGA (16  colors)  cards.
  60.           Planned future  improvements include support for  32768 color VGA
  61.           modes  and Hercules cards as  well. It is  upward compatible with
  62.           the graphics  library in DJGPP  (the C part, no  C++ classes). It
  63.           can use the same drivers  as the graphics library in DJGPP  or it
  64.           can work with a new driver  format supporting programmable number
  65.           of colors as well.
  66.  
  67.  
  68.           Data types, function declarations
  69.  
  70.                All public data structures and graphics primitives meant for
  71.           usage by  the application program are  declared/prototyped in the
  72.           header files (in the 'include' sub-directory):
  73.  
  74.                GRDRIVER.H          graphics driver format specifications
  75.                MOUSEX.H            cursor, mouse and keyboard handling
  76.                GRX.H               drawing-related structures and functions
  77.                GRXFILE.H      file formats and file access routines
  78.                GRXFONT.H      format of a font when loaded into memory
  79.  
  80.  
  81.           Setting video modes
  82.  
  83.                Before  a  program can  do any  graphics  drawing it  has to
  84.           configure  the display adapter of the PC for the desired graphics
  85.           mode. It is done with the 'GrSetMode' function as follows:
  86.  
  87.                  #ifdef __cplusplus
  88.                    void  GrSetMode(int which,int width=0,int height=0,int colors=0);
  89.                  #else
  90.                    void  GrSetMode(int which,...);
  91.                  #endif
  92.  
  93.           The 'mode'  parameter  can be  one  of the  following  constants,
  94.           declared in "grx.h":
  95.  
  96.           typedef enum {
  97.                      GR_80_25_text,
  98.                      GR_default_text,
  99.                      GR_width_height_text,
  100.                      GR_biggest_text,
  101.                      GR_320_200_graphics,
  102.                      GR_default_graphics,
  103.                      GR_width_height_graphics,
  104.                      GR_biggest_noninterlaced_graphics,
  105.                      GR_biggest_graphics,
  106.  
  107.  
  108.  
  109.  
  110.  
  111.                  LIBGRX graphics library user's manual                                                         3
  112.  
  113.  
  114.               GR_width_height_color_graphics
  115.                  } GR_graphics_modes;
  116.  
  117.                The  'GR_width_height_text'  and  'GR_width_height_graphics'
  118.           modes  require   the  two   optional  size  arguments,   and  the
  119.           'GR_width_height_color_graphics' mode requires all three optional
  120.           arguments. A call with any other mode does not require any of the
  121.           optional arguments.
  122.  
  123.           NOTE:  the 'GR_width_height_color_graphics'  mode is  a  new mode
  124.           supported only if: (1) you have a new format graphics driver (see
  125.           the accompanying  documentation in  the file  "DRIVERS.DOC"), and
  126.           (2)  you have a  recent (version 1.06, dated  after the middle of
  127.           April 1992)  copy of GO32  which knows how  to deal with  the new
  128.           driver format.
  129.  
  130.                New  format  graphics  drivers   operating  in  the   proper
  131.           environment (see above)   can  provide a table  of the  supported
  132.           text and graphics modes using the:
  133.  
  134.                  void  GrGetDriverModes(GR_DRIVER_MODE_ENTRY **ttable,GR_DRIVER_MODE_ENTRY **gtable)
  135.  
  136.           function. The arguments 'ttable' and 'gtable' should be addresses
  137.           of pointers  to the  'GR_DRIVER_MODE_ENTRY' structure defined  in
  138.           the include file "grdriver.h".  Upon return the pointer variables
  139.           will point  to two tables  of these structures  one for the  text
  140.           modes,   the  other  for   graphics.  The  'GR_DRIVER_MODE_ENTRY'
  141.           structure has the following fields:
  142.  
  143.           typedef struct {
  144.                      unsigned short  width;
  145.                      unsigned short  height;
  146.                      unsigned short  number_of_colors;
  147.                      unsigned char   BIOS_mode;
  148.                      unsigned char   special;
  149.                  } GR_DRIVER_MODE_ENTRY;
  150.  
  151.                The first four structure members should be obvious,  but the
  152.           'special' field may  deserve some explanation. It is  non-zero if
  153.           the driver does  some special "tricks" to  put the card into  the
  154.           desired mode. An  example might be the 43 row  EGA text mode: for
  155.           this first  the "standard" 80x25 text mode is set up and then the
  156.           character generator  is re-loaded  with  a smaller  font. If  the
  157.           'special' field is zero then the driver simply invokes the INT 10
  158.           function 0 BIOS routine with the mode in the 'BIOS_mode' slot.
  159.  
  160.                A user-defined function can be invoked every time  the video
  161.           mode  is  changed (i.e.  'GrSetMode'  is  called). This  function
  162.           should not take any parameters and  its return value (if any)  is
  163.           ignored.  It can  be  installed (for  all subsequent  'GrSetMode'
  164.           calls) with the:
  165.  
  166.  
  167.  
  168.  
  169.  
  170.                  LIBGRX graphics library user's manual                                                         4
  171.  
  172.  
  173.           void    GrSetModeHook(void (*callback)(void));
  174.  
  175.           function.  The current  graphics mode  (one  of the  valid 'mode'
  176.           argument values for 'GrSetMode') can be obtained with the:
  177.  
  178.           int     GrCurrentMode(void);
  179.  
  180.           function, while the type of the installed graphics adapter can be
  181.           determined with the
  182.  
  183.           int     GrAdapterType(void);
  184.  
  185.           function. 'GrAdapterType' returns  the type of the adapter as one
  186.           of the following three symbolic constants (defined in "grx.h"):
  187.  
  188.           #define GR_VGA          0               /* VGA adapter */
  189.                  #define GR_EGA          1               /* EGA adapter */
  190.                  #define GR_HERC         2               /* Hercules mono adapter */
  191.  
  192.  
  193.           Graphics contexts
  194.  
  195.                The  library  supports  a  set  of  drawing  regions  called
  196.           'contexts'  (the 'GrContext'  structure). These  can be  in video
  197.           memory or in system memory. Contexts in system memory always have
  198.           the  same   memory  organization   as  the  video   memory.  When
  199.           'GrSetMode' is called, a default context is created which maps to
  200.           the  whole  graphics  screen.   Contexts  are  described  by  the
  201.           'GrContext' data structure:
  202.  
  203.                  typedef struct _GR_context_ {
  204.                      char  far *gc_baseaddr;             /* base address of display memory */
  205.                      long  gc_frameaddr;                 /* upper left corner coordinate */
  206.                      long  gc_planeoffset;               /* offset to next color plane */
  207.                      int   gc_lineoffset;                /* offset to next scan line in bytes */
  208.                      char  gc_onscreen;                  /* is it in video memory ? */
  209.                      char  gc_memflags;                  /* memory allocation flags */
  210.                      int   gc_xmax;                      /* max X coord (width  - 1) */
  211.                      int   gc_ymax;                      /* max Y coord (height - 1) */
  212.                      int   gc_xcliplo;                   /* low X clipping limit */
  213.                      int   gc_ycliplo;                   /* low Y clipping limit */
  214.                      int   gc_xcliphi;                   /* high X clipping limit */
  215.                      int   gc_ycliphi;                   /* high Y clipping limit */
  216.                      int   gc_usrxbase;                  /* user window min X coordinate */
  217.                      int   gc_usrybase;                  /* user window min Y coordinate */
  218.                      int   gc_usrwidth;                  /* user window width */
  219.                      int   gc_usrheight;                 /* user window height */
  220.                      int   gc_xoffset;                   /* X offset from root's base */
  221.                      int   gc_yoffset;                   /* Y offset from root's base */
  222.                      struct _GR_context_ *gc_root;       /* context which owns frame buf */
  223.                  } GrContext;
  224.  
  225.  
  226.  
  227.  
  228.  
  229.           LIBGRX graphics library user's manual                                 5
  230.  
  231.  
  232.                There  is  a  subtype  of  the  'GrContext'  structure.  The
  233.           structure  'GrVidRAM' contains only the first  slots of a context
  234.           describing the memory layout of a context. This structure is used
  235.           as  a  component of  other more  complex  data structures  in the
  236.           library.
  237.  
  238.           typedef struct {
  239.                      char  far *gc_baseaddr;             /* base address of display memory */
  240.                      long  gc_frameaddr;                 /* upper left corner coordinate */
  241.                      long  gc_planeoffset;               /* offset to next color plane */
  242.                      int   gc_lineoffset;                /* offset to next scan line in bytes */
  243.                      char  gc_onscreen;                  /* is it in video memory ? */
  244.                      char  gc_memflags;                  /* memory allocation flags */
  245.                  } GrVidRAM;
  246.  
  247.                The following three  functions return information about  the
  248.           layout  of  and memory  occupied by  a  graphics context  of size
  249.           'width' by 'height'  in the current graphics  mode (as set up  by
  250.           'GrSetMode'):
  251.  
  252.           int     GrLineOffset(int width);
  253.                  long    GrPlaneSize(int w,int h);
  254.                  long    GrContextSize(int w,int h);
  255.  
  256.           'GrLineOffset' always returns the offset between successive pixel
  257.           rows  of the  context  in bytes.  'GrContextSize' calculates  the
  258.           total amount of  memory needed by a  context, while 'GrPlaneSize'
  259.           calculates the size of a bitplane in the context. (It will be the
  260.           same  as the  size of  the full  context in  256 and  32768 color
  261.           modes.) The function:
  262.  
  263.           GrContext *GrCreateContext(int w,int h,char far *memory,GrContext *where);
  264.  
  265.           can be  used to create a  new context in system  memory. The NULL
  266.           pointer is also accepted as the value of the 'memory' and 'where'
  267.           arguments,  in  this case  the  library  allocates the  necessary
  268.           amount of memory internally.
  269.  
  270.                It is  a general  convention in the  library that  functions
  271.           returning  pointers to any LIBGRX  specific data structure have a
  272.           last  argument (most of the time named 'where' in the prototypes)
  273.           which can be used to pass the address of the data structure which
  274.           should be filled with the result. If this 'where' pointer has the
  275.           value  of NULL,  then the  library allocates  space for  the data
  276.           structure internally. 
  277.  
  278.           The function:
  279.  
  280.           GrContext *GrCreateSubContext(int x1,int y1,int x2,int y2,GrContext *parent,GrContext *where);
  281.  
  282.  
  283.  
  284.  
  285.  
  286.           LIBGRX graphics library user's manual                                 6
  287.  
  288.  
  289.           creates a  new sub-context which  maps to  a part of  an existing
  290.           context.  The  coordinate  arguments  ('x1'   through  'y2')  are
  291.           interpreted  relative  to  the  parent  context's  limits.  Pixel
  292.           addressing is  zero-based even in sub-contexts,  i.e. the address
  293.           of the  top left pixel is  (0,0) even in a  sub-context which has
  294.           been mapped onto the interior of its parent context.
  295.  
  296.                Sub-contexts  can be  resized, but  not their  parents (i.e.
  297.           anything returned  by 'GrCreateContext' or set  up by 'GrSetMode'
  298.           cannot be resized  -- because  this could  lead to  irrecoverable
  299.           "loss"  of drawing memory. The following function can be used for
  300.           this purpose:
  301.  
  302.           void    GrResizeSubContext(GrContext *context,int x1,int y1,int x2,int y2);
  303.  
  304.                The current context structure is stored in a static location
  305.           in  the  library. (For  efficiency reasons  --  it is  used quite
  306.           frequently, and this way  no pointer dereferencing is necessary.)
  307.           The  context  stores all  relevant  information  about the  video
  308.           organization, coordinate  limits, etc... The  current context can
  309.           be set with the:
  310.  
  311.           void    GrSetContext(GrContext *context);
  312.  
  313.           function.  This function  will reset the  current context  to the
  314.           full  graphics screen  if  it  is  passed  the  NULL  pointer  as
  315.           argument. The value  of the current context  can be saved  into a
  316.           'GrContext' structure pointed to by 'where' using:
  317.  
  318.           GrContext *GrSaveContext(GrContext *where);
  319.  
  320.           (Again, if  'where' is  NULL, the  library allocates  the space.)
  321.           Contexts can be destroyed with: 
  322.  
  323.           void    GrDestroyContext(GrContext *context);
  324.  
  325.           This function will free  the memory occupied by the  context only
  326.           if it was allocated originally by the library. 
  327.  
  328.           The next three  functions set  up and query  the clipping  limits
  329.           associated with the context:
  330.  
  331.           void    GrSetClipBox(int x1,int y1,int x2,int y2);
  332.                  void    GrGetClipBox(int *x1p,int *y1p,int *x2p,int *y2p);
  333.                  void    GrResetClipBox(void);
  334.  
  335.           'GrResetClipBox'  sets  the  clipping  limits to  the  limits  of
  336.           context.  These are the limits set up initially when a context is
  337.           created.  The limits of the current context can be obtained using
  338.           the following functions:
  339.  
  340.  
  341.  
  342.  
  343.  
  344.                  LIBGRX graphics library user's manual                                                         7
  345.  
  346.  
  347.           int     GrMaxX(void);
  348.                  int     GrMaxY(void);
  349.                  int     GrSizeX(void);
  350.                  int     GrSizeY(void);
  351.  
  352.           The 'Max'  functions return  the biggest valid  coordinate, while
  353.           the 'Size' functions return a value one higher. The limits of the
  354.           graphics  screen  (regardless  of  the current  context)  can  be
  355.           obtained with: 
  356.  
  357.           int     GrScreenX(void);
  358.                  int     GrScreenY(void);
  359.  
  360.  
  361.           Color management
  362.  
  363.                The library supports two models for color management. In the
  364.           'indirect' (or color table) mode colors can be allocated with the
  365.           highest resolution supported by the hardware (EGA: 2 bits, VGA: 6
  366.           bits) with  respect to the  component color  intensities. In  the
  367.           'direct'  or RGB mode  color indices map  directly into component
  368.           color intensities  with non-overlapping  bitfields  of the  color
  369.           index  representing  the  component   colors.  The  RGB  mode  is
  370.           supported in 256 color and 32768 color VGA  modes only (for 32768
  371.           colors this is  the only mode  because of the limitations  of the
  372.           VGA  hardware with HiColor DAC). In RGB mode the color index maps
  373.           to component color intensities as follows:
  374.  
  375.               256:  rrrgggbb       (3 bits for red and green, 2 for blue)
  376.               32768:     xrrrrrgggggbbbbb    (5  bits  for  each  component
  377.           color)
  378.  
  379.                The RGB  mode is not supported in 16 color EGA and VGA modes
  380.           as  there  are  too  few  available  colors  to  provide adequate
  381.           coverage.  The   advantage  of  the  RGB  mode  is  faster  color
  382.           allocation  (no table  lookup, DAC register  programming, etc...)
  383.           its  disadvantage is  the relatively  crude approximation  of the
  384.           component color intensities.
  385.  
  386.                After  the  first 'GrSetMode'  call  two  colors are  always
  387.           defined: black and  white. The  indices of these  two colors  are
  388.           returned by the functions:
  389.  
  390.           int     GrBlack(void);
  391.                  int     GrWhite(void);
  392.  
  393.           NOTE:  unlike  the  original   DJGPP  library,  LIBGRX  does  not
  394.           guarantee that the white color
  395.           has the color index value of one. (GrBlack still returns 0). 
  396.  
  397.  
  398.  
  399.  
  400.  
  401.           LIBGRX graphics library user's manual                                 8
  402.  
  403.  
  404.                The library  supports four write modes:  write, XOR, logical
  405.           OR and logical AND. These  can be selected with OR-ing the  color
  406.           index with one of the following constants declared in "grx.h":
  407.  
  408.           #ifdef __TURBOC__
  409.                  # define GrXOR          0x100           /* to "XOR" any color to the screen */
  410.                  # define GrOR           0x200           /* to "OR" to the screen */
  411.                  # define GrAND          0x300           /* to "AND" to the screen */
  412.                  #endif
  413.                  #ifdef __GNUC__                         /* changed for 16 bit colors */
  414.                  # define GrXOR          0x10000         /* to "XOR" any color to the screen */
  415.                  # define GrOR           0x20000         /* to "OR" to the screen */
  416.                  # define GrAND          0x30000         /* to "AND" to the screen */
  417.                  #endif
  418.                  #define GrWRITE         0               /* write color */
  419.                  #define GrNOCOLOR       (GrXOR | 0)     /* GrNOCOLOR is used for "no" color */
  420.  
  421.           NOTE:  'GrXOR' was declared to  be "0x100" in  the original DJGPP
  422.           library,  but  its  value   had  to  be  changed  in   LIBGRX  in
  423.           anticipation of the 32768 color VGA support.
  424.  
  425.           By convention,  the no-op  color is  obtained by combining  color
  426.           index 0 (black) with the XOR operation. This no-op color has been
  427.           defined in "grx.h" as 'GrNOCOLOR'.
  428.  
  429.           The  number of colors in the current graphics mode is returned by
  430.           the:
  431.  
  432.           int     GrNumColors(void);
  433.  
  434.           function,  while the  number of  unused, available  color  can be
  435.           obtained by calling:
  436.  
  437.           int     GrNumFreeColors(void);
  438.  
  439.           Colors can be allocated with the:
  440.  
  441.           int     GrAllocColor(int r,int g,int b);
  442.  
  443.           function (component intensities can range from 0 to 255), or with
  444.           the:
  445.  
  446.           int     GrAllocCell(void);
  447.  
  448.           function. In  the second  case the  component intensities  of the
  449.           returned color can be set with:
  450.  
  451.           void    GrSetColor(int color,int r,int g,int b);
  452.  
  453.           Both 'Alloc'  functions return 'GrNOCOLOR'  if there are  no more
  454.           free colors available. Additionally 'GrAllocCell'  always returns
  455.  
  456.  
  457.  
  458.  
  459.  
  460.           LIBGRX graphics library user's manual                                 9
  461.  
  462.  
  463.           'GrNOCOLOR'  when  the color  system is  in  RGB mode,  as colors
  464.           returned by 'GrAllocCell' are meant to be changed  -- what is not
  465.           supposed  to be done in  RGB mode. Also  note that 'GrAllocColor'
  466.           operates much more  efficiently in  RGB mode, and  that it  never
  467.           returns 'GrNOCOLOR' in this case.
  468.  
  469.           Color  table  entries can  be  freed (when  not in  RGB  mode) by
  470.           calling:
  471.  
  472.           void    GrFreeColor(int color);
  473.  
  474.           The component intensities of  any color can be queried  using the
  475.           function:
  476.  
  477.           void    GrQueryColor(int c,int *r,int *g,int *b);
  478.  
  479.                Initially  the color  system  is in  color table  (indirect)
  480.           mode. (Except for the  32768 color VGA modes which are  always in
  481.           RGB  mode.) 256 color VGA  modes can be put  into the RGB mode by
  482.           calling:
  483.  
  484.           void    GrSetRGBcolorMode(void);
  485.  
  486.           The  color system can  be reset (i.e.  put back  into color table
  487.           mode if possible, all colors freed except for black and white) by
  488.           calling:
  489.  
  490.           void    GrResetColors(void);
  491.  
  492.           The function:
  493.  
  494.           void    GrRefreshColors(void);
  495.  
  496.           reloads  the  currently allocated  color  values  into the  video
  497.           hardware. This  function is  not needed in  typical applications,
  498.           unless  the  display  adapter   is  programmed  directly  by  the
  499.           application.
  500.  
  501.           Graphics primitives
  502.  
  503.                The  screen, the current context or the current clip box can
  504.           be cleared (i.e. set to a desired background color) by using  one
  505.           of the following three functions:
  506.  
  507.           void    GrClearScreen(int bg);
  508.                  void    GrClearContext(int bg);
  509.                  void    GrClearClipBox(int bg);
  510.  
  511.           The following  line drawing graphics primitives  are supported by
  512.           the library:
  513.  
  514.  
  515.  
  516.  
  517.  
  518.                  LIBGRX graphics library user's manual                                                       10
  519.  
  520.  
  521.           void    GrPlot(int x,int y,int c);
  522.                  void    GrLine(int x1,int y1,int x2,int y2,int c);
  523.                  void    GrHLine(int x1,int x2,int y,int c);
  524.                  void    GrVLine(int x,int y1,int y2,int c);
  525.                  void    GrBox(int x1,int y1,int x2,int y2,int c);
  526.                  void    GrCircle(int xc,int yc,int r,int c);
  527.                  void    GrEllipse(int xc,int yc,int xa,int ya,int c);
  528.                  void    GrCircleArc(int xc,int yc,int r,int start,int end,int c);
  529.                  void    GrEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  530.                  void    GrPolyLine(int numpts,int points[][2],int c);
  531.                  void    GrPolygon(int numpts,int points[][2],int c);
  532.  
  533.                All primitives operate on  the current graphics context. The
  534.           last argument of these functions is always the color index to use
  535.           for the  drawing.  The 'HLine'  and  'VLine' primitives  are  for
  536.           drawing horizontal and vertical lines. They have been included in
  537.           the library because they are more efficient than the general line
  538.           drawing  provided by  'GrLine'. The  ellipse primitives  can only
  539.           draw ellipses with their major axis parallel with either the X or
  540.           Y coordinate axis. They take the half X and Y  axis length in the
  541.           'xa' and  'ya' arguments.  The arc (circle  and ellipse)  drawing
  542.           functions  take the  start and  end angles  in tenths  of degrees
  543.           (i.e. meaningful range:  0 ... 3600). The  angles are interpreted
  544.           counter-clockwise starting from the positive X axis. The polyline
  545.           and polygon  primitives take the address of  an n by 2 coordinate
  546.           array. The  X values  should be  stored  in the  elements with  0
  547.           second  index, and  the Y  values in  the elements with  a second
  548.           index  value  of  1.  Coordinate  arrays passed  to  the  polygon
  549.           primitives can either  contain or  omit the closing  edge of  the
  550.           polygon --  the primitive will  append it  to the list  if it  is
  551.           missing.
  552.  
  553.           The following filled primitives are available:
  554.  
  555.           void    GrFilledBox(int x1,int y1,int x2,int y2,int c);
  556.                  void    GrFramedBox(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
  557.                  void    GrFilledCircle(int xc,int yc,int r,int c);
  558.                  void    GrFilledEllipse(int xc,int yc,int xa,int ya,int c);
  559.                  void    GrFilledCircleArc(int xc,int yc,int r,int start,int end,int c);
  560.                  void    GrFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  561.                  void    GrFilledPolygon(int numpts,int points[][2],int c);
  562.  
  563.                Similarly to  the line drawing, all of  the above primitives
  564.           operate  on  the  current  graphics  context.  The  'GrFramedBox'
  565.           primitive  can  be  used  to draw  motif-like  shaded  boxes  and
  566.           "ordinary"  framed   boxes  as   well.  The  'x1'   through  'y2'
  567.           coordinates specify  the  interior  of  the box,  the  border  is
  568.           outside this area.  The primitive uses five different  colors for
  569.           the interior and four borders of  the box which are specified  in
  570.           the 'GrFBoxColors' structure:
  571.  
  572.  
  573.  
  574.  
  575.  
  576.                  LIBGRX graphics library user's manual                                                       11
  577.  
  578.  
  579.           typedef struct {
  580.                      int  fbx_intcolor;
  581.                      int  fbx_topcolor;
  582.                      int  fbx_rightcolor;
  583.                      int  fbx_bottomcolor;
  584.                      int  fbx_leftcolor;
  585.                  } GrFBoxColors;
  586.  
  587.           The current color  value of any pixel in  the current context can
  588.           be obtained with:
  589.  
  590.           int     GrPixel(int x,int y);
  591.  
  592.           Rectangular areas can be transferred  within a context or between
  593.           contexts by calling:
  594.  
  595.           void    GrBitBlt(GrContext *dest,int x,int y,GrContext *source,int x1,int y1,int x2,int y2,int oper);
  596.  
  597.           The  'oper'  argument  should be  one  of  supported color  modes
  598.           (write, XOR, OR, AND),  it will control  how the pixels from  the
  599.           source  context are combined  with the pixels  in the destination
  600.           context. If either the source or the destination context argument
  601.           is the  NULL pointer then  the current  context is used  for that
  602.           argument.
  603.  
  604.  
  605.           Non-clipping graphics primitives
  606.  
  607.                There is  a non-clipping version  of some of  the elementary
  608.           primitives. These  are somewhat  more efficient than  the regular
  609.           versions. These  are to  be used only  in situations  when it  is
  610.           absolutely certain that  no drawing will be  performed beyond the
  611.           boundaries  of the  current context.  Otherwise the  program will
  612.           almost certainly crash! The  reason for including these functions
  613.           is  that  they  are somewhat  more  efficient  than  the regular,
  614.           clipping versions.  ALSO NOTE:  These function  do not  check for
  615.           conflicts with the mouse  cursor. (See the explanation  about the
  616.           mouse  cursor handling later in  this document.) The  list of the
  617.           supported non-clipping primitives:
  618.  
  619.           void    GrPlotNC(int x,int y,int c);
  620.                  void    GrLineNC(int x1,int y1,int x2,int y2,int c);
  621.                  void    GrHLineNC(int x1,int x2,int y,int c);
  622.                  void    GrVLineNC(int x,int y1,int y2,int c);
  623.                  void    GrBoxNC(int x1,int y1,int x2,int y2,int c);
  624.                  void    GrFilledBoxNC(int x1,int y1,int x2,int y2,int c);
  625.                  void    GrFramedBoxNC(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
  626.                  void    GrBitBltNC(GrContext *dst,int x,int y,GrContext *src,int x1,int y1,int x2,int y2,int oper);
  627.                  int     GrPixelNC(int x,int y);
  628.  
  629.  
  630.  
  631.  
  632.  
  633.           LIBGRX graphics library user's manual                                12
  634.  
  635.  
  636.           Customized line drawing
  637.  
  638.                The   basic  line  drawing   graphics  primitives  described
  639.           previously always draw continuous lines which are one pixel wide.
  640.           There is another  group of  line drawing functions  which can  be
  641.           used  to draw wide  and/or patterned lines.  These functions have
  642.           similar parameter passing conventions as the basic ones with  one
  643.           difference: instead of the  color value a pointer to  a structure
  644.           of type 'GrLineOption' has  to be passed to them.  The definition
  645.           of the 'GrLineOption' structure:
  646.  
  647.           typedef struct {
  648.                      int  lno_color;                     /* color used to draw line */
  649.                      int  lno_width;                     /* width of the line */
  650.                      int  lno_pattlen;                   /* length of the dash pattern */
  651.                      unsigned char *lno_dashpat;         /* draw/nodraw pattern */
  652.                  } GrLineOption;
  653.  
  654.           The 'lno_pattlen' structure element should be equal to the number
  655.           of alternating draw -- no draw section length values in the array
  656.           pointed to by  the 'lno_dashpat' element. The dash  pattern array
  657.           is  assumed to begin with a drawn  section. If the pattern length
  658.           is equal to zero a continuous line is drawn. The available custom
  659.           line drawing primitives:
  660.  
  661.           void    GrCustomLine(int x1,int y1,int x2,int y2,GrLineOption *o);
  662.                  void    GrCustomBox(int x1,int y1,int x2,int y2,GrLineOption *o);
  663.                  void    GrCustomCircle(int xc,int yc,int r,GrLineOption *o);
  664.                  void    GrCustomEllipse(int xc,int yc,int xa,int ya,GrLineOption *o);
  665.                  void    GrCustomCircleArc(int xc,int yc,int r,int start,int end,GrLineOption *o);
  666.                  void    GrCustomEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLineOption *o);
  667.                  void    GrCustomPolyLine(int numpts,int points[][2],GrLineOption *o);
  668.                  void    GrCustomPolygon(int numpts,int points[][2],GrLineOption *o);
  669.  
  670.  
  671.           Pattern filled graphics primitives
  672.  
  673.                The library  also supports a  pattern filled version  of the
  674.           basic filled  primitives  described above.  These functions  have
  675.           similar parameter passing  conventions as the basic ones with one
  676.           difference:  instead of the color value  a pointer to an union of
  677.           type  'GrPattern' has to be passed to them. The 'GrPattern' union
  678.           can contain either a bitmap  or a pixmap fill pattern.  The first
  679.           integer slot in  the union  determines which type  it is.  Bitmap
  680.           fill  patterns  are rectangular  arrays  of  bits, each  set  bit
  681.           representing the foreground color of the fill operation, and each
  682.           zero  bit representing  the background.  Both the  foreground and
  683.           background colors  can  be combined  with  any of  the  supported
  684.           logical operations.  Bitmap fill  patterns have  one restriction:
  685.           their width must be  eight pixels. Pixmap fill patterns  are very
  686.           similar  to  contexts,  the  data is  transferred  to  the filled
  687.  
  688.  
  689.  
  690.  
  691.  
  692.           LIBGRX graphics library user's manual                                13
  693.  
  694.  
  695.           primitive  using  'BitBlt'  operations.  The  relevant  structure
  696.           declarations (from "grx.h"):
  697.  
  698.           /*
  699.                   * BITMAP: a mode independent way to specify a fill pattern of two
  700.                   *   colors. It is always 8 pixels wide (1 byte per scan line), its
  701.                   *   height is user-defined. SET THE TYPE FLAG TO ZERO!!!
  702.                   */
  703.                  typedef struct {
  704.                      int  bmp_ispixmap;                  /* type flag for pattern union */
  705.                      int  bmp_height;                    /* bitmap height */
  706.                      unsigned char *bmp_data;            /* pointer to the bit pattern */
  707.                      int  bmp_fgcolor;                   /* foreground color for fill */
  708.                      int  bmp_bgcolor;                   /* background color for fill */
  709.                      int  bmp_memflags;                  /* set if dynamically allocated */
  710.                  } GrBitmap;
  711.  
  712.                  /*
  713.                   * PIXMAP: a fill pattern stored in a layout identical to the video RAM
  714.                   *   for filling using 'bitblt'-s. It is mode dependent, typically one
  715.                   *   of the library functions is used to build it. KEEP THE TYPE FLAG
  716.                   *   NONZERO!!!
  717.                   */
  718.                  typedef struct {
  719.                      int  pxp_ispixmap;                  /* type flag for pattern union */
  720.                      int  pxp_width;                     /* pixmap width (in pixels)  */
  721.                      int  pxp_height;                    /* pixmap height (in pixels) */
  722.                      int  pxp_oper;                      /* bitblt mode (SET, OR, XOR, AND) */
  723.                      GrVidRAM pxp_source;                /* source context for fill */
  724.                  } GrPixmap;
  725.  
  726.                  /*
  727.                   * Fill pattern union -- can either be a bitmap or a pixmap
  728.                   */
  729.                  typedef union {
  730.                      int      gp_ispixmap;               /* nonzero for pixmaps */
  731.                      GrBitmap gp_bitmap;                 /* fill bitmap */
  732.                      GrPixmap gp_pixmap;                 /* fill pixmap */
  733.                  } GrPattern;
  734.  
  735.                  #define gp_bmp_data                     gp_bitmap.bmp_data
  736.                  #define gp_bmp_height                   gp_bitmap.bmp_height
  737.                  #define gp_bmp_fgcolor                  gp_bitmap.bmp_fgcolor
  738.                  #define gp_bmp_bgcolor                  gp_bitmap.bmp_bgcolor
  739.  
  740.                  #define gp_pxp_width                    gp_pixmap.pxp_width
  741.                  #define gp_pxp_height                   gp_pixmap.pxp_height
  742.                  #define gp_pxp_oper                     gp_pixmap.pxp_oper
  743.                  #define gp_pxp_source                   gp_pixmap.pxp_source
  744.  
  745.  
  746.  
  747.  
  748.  
  749.           LIBGRX graphics library user's manual                                14
  750.  
  751.  
  752.           Bitmap patterns  can be  easily built from  initialized character
  753.           arrays and static structures  by the C compiler, thus  no special
  754.           support  is included in the  library for creating  them. The only
  755.           action required  from the  application program might  be changing
  756.           the foreground  and background colors as  needed. Pixmap patterns
  757.           are more difficult  to build as they replicate the  layout of the
  758.           video memory which  changes for different  video modes. For  this
  759.           reason  the library  provides  three functions  to create  pixmap
  760.           patterns in a mode-independent way:
  761.  
  762.           GrPattern *GrBuildPixmap(char *pixels,int w,int h,GrColorTableP colors);
  763.                  GrPattern *GrBuildPixmapFromBits(char *bits,int w,int h,int fgc,int bgc);
  764.                  GrPattern *GrConvertToPixmap(GrContext *src);
  765.  
  766.           'GrBuildPixmap'  build a pixmap  from a  two dimensional  ('w' by
  767.           'h') array of  characters. The elements in this array are used as
  768.           indices  into  the  color   table  specified  with  the  argument
  769.           'colors'.  (This means that pixmaps  created this way  can use at
  770.           most 256 colors.) The color table pointer:
  771.  
  772.           typedef int *GrColorTableP;
  773.  
  774.           should point to an array of integers with the first element being
  775.           the  number  of  colors  in  the  table  and  the  color  indices
  776.           themselves  starting with  the  second element.  NOTE: any  color
  777.           modifiers (GrXOR, GrOR, GrAND) OR-ed to the elements of the color
  778.           table are ignored.
  779.  
  780.           The 'GrBuildPixmapFromBits' function builds a pixmap fill pattern
  781.           from bitmap data. It is useful if the width of the bitmap pattern
  782.           is not eight  as such bitmap patterns can not be  used to build a
  783.           'GrBitmap' structure.
  784.  
  785.           The 'GrConvertToPixmap' function converts a graphics context to a
  786.           pixmap fill pattern. It is useful when the pattern can be created
  787.           with graphics  drawing operations.  NOTE: the pixmap  pattern and
  788.           the original context share  the drawing RAM, thus if  the context
  789.           is redrawn the fill pattern changes as well. 
  790.  
  791.                Fill patterns which  were built by  library routines can  be
  792.           destroyed  when no longer needed (i.e. the space occupied by them
  793.           can be freed) by calling:
  794.  
  795.           void    GrDestroyPattern(GrPattern *p);
  796.  
  797.           NOTE:  when  pixmap fill  patterns  converted  from contexts  are
  798.           destroyed, the drawing  RAM is not  freed. It is  freed when  the
  799.           original  context  is  destroyed.  Fill  patterns  built  by  the
  800.           application have to be  destroyed by the application as  well (if
  801.           this is needed). 
  802.  
  803.  
  804.  
  805.  
  806.  
  807.           LIBGRX graphics library user's manual                                15
  808.  
  809.  
  810.                The list of supported  pattern filled graphics primitives is
  811.           shown  below. These  functions  are very  similar to  their solid
  812.           filled counterparts, only their last argument is different:
  813.  
  814.           void    GrPatternedPlot(int x,int y,GrPattern *p);
  815.                  void    GrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p);
  816.                  void    GrPatternFilledCircle(int xc,int yc,int r,GrPattern *p);
  817.                  void    GrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p);
  818.                  void    GrPatternFilledCircleArc(int xc,int yc,int r,int start,int end,GrPattern *p);
  819.                  void    GrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrPattern *p);
  820.                  void    GrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p);
  821.  
  822.  
  823.           Patterned line drawing
  824.  
  825.                The custom line drawing functions introduced above also have
  826.           a version when the drawn sections can be filled with a (pixmap or
  827.           bitmap) fill  pattern. To  achieve this  these functions  must be
  828.           passed  both   a  custom  line  drawing   option  ('GrLineOption'
  829.           structure) and a fill pattern ('GrPattern' union). These two have
  830.           been combined into the 'GrLinePattern' structure:
  831.  
  832.           typedef struct {
  833.                      GrPattern     *lnp_pattern;         /* fill pattern */
  834.                      GrLineOption  *lnp_option;          /* width + dash pattern */
  835.                  } GrLinePattern;
  836.  
  837.           All  patterned  line drawing  functions  take a  pointer  to this
  838.           structure  as   their  last  argument.  The   list  of  available
  839.           functions:
  840.  
  841.           void    GrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  842.                  void    GrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  843.                  void    GrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp);
  844.                  void    GrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp);
  845.                  void    GrPatternedCircleArc(int xc,int yc,int r,int start,int end,GrLinePattern *lp);
  846.                  void    GrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLinePattern *lp);
  847.                  void    GrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp);
  848.                  void    GrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp);
  849.  
  850.  
  851.           Text drawing
  852.  
  853.                The   library  supports   loadable   bit-mapped  (i.e.   not
  854.           scalable!) fonts.  Some of  these fonts  were converted  from VGA
  855.           BIOS  fonts and fonts on utility diskettes coming with VGA cards.
  856.           These  fonts have all 256 characters.  Some additional fonts were
  857.           converted from X fonts  from a UNIX workstation. These  have only
  858.           128  characters.   The  naming  conventions  for   the  currently
  859.           available fonts are as follows:
  860.  
  861.  
  862.  
  863.  
  864.  
  865.           LIBGRX graphics library user's manual                                16
  866.  
  867.  
  868.                pc<width>x<height>.fnt        BIOS  font   (fixed)  of  size
  869.           width x height
  870.                pc<width>x<height>t.fnt       BIOS  font  (fixed,  thin)  of
  871.           size width x height
  872.                xm<width>x<height>.fnt        X11 font (fixed) of size width
  873.           x height
  874.                xm<width>x<height>b.fnt  X11  font  (fixed,  bold)  of  size
  875.           width x height
  876.                xm<width>x<height>i.fnt  X11  font  (fixed, italic)  of size
  877.           width x height
  878.  
  879.           Fonts also have family names, currently available fonts belong to
  880.           one of the following:
  881.  
  882.                "pc"                     BIOS font
  883.                "pc_thin"                BIOS font, thin
  884.                "X_misc"                 X11 font, miscellaneous group (from
  885.                                         the original  MIT distribution, can
  886.                                         be copied freely)
  887.                "X_misc_bold"            X11 font, bold, miscellaneous group
  888.                "X_misc_ital"            X11  font,   italic,  miscellaneous
  889.           group
  890.  
  891.                Fonts are loaded with the 'GrLoadFont' function. If the font
  892.           file name contains any path separator character (':', '/' or '\')
  893.           then  it is  loaded from  the specified directory,  otherwise the
  894.           font is loaded from the  default font path. The font path  can be
  895.           set up with the 'GrSetFontPath' function. If the font path is not
  896.           set  then the value of the 'GRXFONT' environment variable is used
  897.           as  the font path. If 'GrLoadFont'  is called again with the name
  898.           of an  already loaded font then  it will return a  pointer to the
  899.           result   of   the  first   loading.   The   special  font   names
  900.           "@:pc8x8.fnt",  "@:pc8x14.fnt"  and  "@:pc8x16.fnt"   will  cause
  901.           'GrLoadFont' to load the font from  the BIOS of the graphics card
  902.           of the PC (provided that it has the desired font). Alternatively,
  903.           'GrLoadBIOSFont'  can also be called to load a font which resides
  904.           in  the  BIOS of  the display  adapter.  (The difference  is that
  905.           'GrLoadFont' will look  at the disk as well if  the BIOS does not
  906.           have  the font. For  example: EGA-s don't  have a 16  row font in
  907.           their BIOS.) Both font  loading routines return NULL if  the font
  908.           was not  found. When not  needed any more, fonts  can be unloaded
  909.           (i.e.   the  storage   occupied   by  them   freed)  by   calling
  910.           'GrUnloadFont'. The prototype declarations for these functions:
  911.  
  912.           GrFont *GrLoadFont(char *name);
  913.                  GrFont *GrLoadBIOSFont(char *name);
  914.                  void    GrUnloadFont(GrFont *font);
  915.                  void    GrSetFontPath(char *path);
  916.  
  917.                The 'GrFont' structure  is actually a font  header, the real
  918.           font  data is  right next  to this  header in  memory, but  it is
  919.  
  920.  
  921.  
  922.  
  923.  
  924.           LIBGRX graphics library user's manual                                17
  925.  
  926.  
  927.           typically  hidden from  the application  program. If  needed, the
  928.           include file  "grxfont.h" can provide more  details. The 'GrFont'
  929.           structure:
  930.  
  931.           typedef struct {
  932.                      short   fnt_width;                  /* width (average for proportional) */
  933.                      short   fnt_height;                 /* font height */
  934.                      short   fnt_minchar;                /* lowest character code in font */
  935.                      short   fnt_maxchar;                /* highest character code in font */
  936.                      short   fnt_isfixed;                /* nonzero if fixed font */
  937.                      short   fnt_internal;               /* nonzero if BIOS font */
  938.                      short   fnt_baseline;               /* baseline from top of font */
  939.                      short   fnt_undwidth;               /* underline width (at bottom) */
  940.                      char    fnt_name[GR_NAMEWIDTH];     /* font file name (w/o path) */
  941.                      char    fnt_family[GR_NAMEWIDTH];   /* font family name */
  942.                  } GrFont;
  943.  
  944.                There is a function: 'GrFindBestFont' which returns the font
  945.           which matches best a  desired size. (Best match: not  bigger, but
  946.           as close  as possible). The  application can  specify whether  it
  947.           wants  'GrFindBestFont' to  find the  best  match using  fonts in
  948.           their  original sizes only, or  possibly enlarged (with the value
  949.           of   the   'magnify'   argument   --  0:   no,   nonzero:   yes).
  950.           'GrFindBestFont' also takes a string argument which specifies the
  951.           font family from which to select the font. The string can specify
  952.           several  family patterns  separated  by the  ':' character.  Each
  953.           pattern can  contain the  '?' and  '*' wildcard  characters which
  954.           work the  usual way (in  UNIX sense  -- i.e. "X*ital"  will match
  955.           "X_misc_ital", but not "X_misc_bold"..).
  956.  
  957.           GrTextOption *GrFindBestFont(int width,int height,int magnify,char *family,GrTextOption *where);
  958.  
  959.           The 'GrTextOption'  structure specifies  how to draw  a character
  960.           string:
  961.  
  962.           typedef struct {
  963.                      GrFont *txo_font;                   /* font to be used */
  964.                      int     txo_xmag;                   /* X magnification */
  965.                      int     txo_ymag;                   /* Y magnification */
  966.                      union {
  967.                          int v;                          /* color when no attributes */
  968.                          GrColorTableP p;                /* ptr to color table otherwise */
  969.                      } txo_fgcolor,txo_bgcolor;          /* foreground, background */
  970.                      char    txo_direct;                 /* direction */
  971.                      char    txo_xalign;                 /* X alignment */
  972.                      char    txo_yalign;                 /* Y alignment */
  973.                      char    txo_chrtype;                /* character type */
  974.                  } GrTextOption;
  975.  
  976.           The font can be enlarged independently in the X and Y directions,
  977.           ('txo_xmag'  and 'txo_ymag' slots --  values: 1 and  up) the text
  978.  
  979.  
  980.  
  981.  
  982.  
  983.           LIBGRX graphics library user's manual                                18
  984.  
  985.  
  986.           can  be  rotated  in  increments of  90  degrees  ('txo_direct'),
  987.           alignments  can  be  set  in both  directions  ('txo_xalign'  and
  988.           'txo_yalign'),  and separate  fore and  background colors  can be
  989.           specified. The accepted text direction values:
  990.  
  991.           #define GR_TEXT_RIGHT           0       /* normal */
  992.                  #define GR_TEXT_DOWN            1       /* downward */
  993.                  #define GR_TEXT_LEFT            2       /* upside down, right to left */
  994.                  #define GR_TEXT_UP              3       /* upward */
  995.                  #define GR_TEXT_DEFAULT         GR_TEXT_RIGHT
  996.  
  997.           The accepted horizontal and vertical alignment option values:
  998.  
  999.           #define GR_ALIGN_LEFT           0       /* X only */
  1000.                  #define GR_ALIGN_TOP            0       /* Y only */
  1001.                  #define GR_ALIGN_CENTER         1       /* X, Y */
  1002.                  #define GR_ALIGN_RIGHT          2       /* X only */
  1003.                  #define GR_ALIGN_BOTTOM         2       /* Y only */
  1004.                  #define GR_ALIGN_BASELINE       3       /* Y only */
  1005.                  #define GR_ALIGN_DEFAULT        GR_ALIGN_LEFT
  1006.  
  1007.           Text strings can be  of three different types: one  character per
  1008.           byte  (i.e. the usual C  character string, this  is the default),
  1009.           one  character per 16-bit word  (suitable for fonts  with a large
  1010.           number  of characters), and  a PC-style character-attribute pair.
  1011.           In the  last case  the 'GrTextOption'  structure  must contain  a
  1012.           pointer to a color table of size  16 (fg color bits in attrib) or
  1013.           8 (bg color  bits). (The color table format is  explained in more
  1014.           detail in  the previous section  explaining the methods  to build
  1015.           fill patterns.) The supported text types:
  1016.  
  1017.           #define GR_BYTE_TEXT            0       /* one byte per character */
  1018.                  #define GR_WORD_TEXT            1       /* two bytes per character */
  1019.                  #define GR_ATTR_TEXT            2       /* chr w/ PC style attribute byte */
  1020.  
  1021.           The PC-style  attribute text  uses the  same layout  (first byte:
  1022.           character,  second: attributes)  and bitfields  as the  text mode
  1023.           screen on the PC. The only  difference is that the 'blink' bit is
  1024.           not supported  (it would be  very time  consuming -- the  PC text
  1025.           mode does it with hardware support). This  bit is used instead to
  1026.           control the underlined display of characters. For convenience the
  1027.           following  attribute manipulation  macros have  been declared  in
  1028.           "grx.h":
  1029.  
  1030.           #define GR_BUILD_ATTR(fgcolor,bgcolor,underline)  \
  1031.                      ((fgcolor) & 15) | (((bgcolor) & 7) << 4) | (((underline) & 1) << 7))
  1032.                  #define GR_ATTR_FGCOLOR(attr)   ((attr) & 15)
  1033.                  #define GR_ATTR_BGCOLOR(attr)   (((attr) >> 4) & 7)
  1034.                  #define GR_ATTR_UNDERLINE(attr) (((attr) >> 7) & 1)
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.           LIBGRX graphics library user's manual                                19
  1041.  
  1042.  
  1043.           After the  application initializes  a text option  structure with
  1044.           the  desired values it  can call  one of  the following  two text
  1045.           drawing functions:
  1046.  
  1047.           void    GrDrawChar(int chr,int x,int y,GrTextOption *opt);
  1048.                  void    GrDrawString(char *text,int length,int x,int y,GrTextOption *opt);
  1049.  
  1050.  
  1051.           NOTE: text drawing is fastest when the font is not magnified,  it
  1052.           is  drawn in the 'normal'  direction, and the  character does not
  1053.           have to  be  clipped.  It  this  case the  library  can  use  the
  1054.           appropriate    low-level   video   RAM    access   routine   (see
  1055.           "INTERNAL.DOC" for  more details),  while in  any other case  the
  1056.           text  is  drawn   pixel-by-pixel  (or  rectangle-by-rectangle  if
  1057.           enlarged) by the higher-level code.
  1058.  
  1059.                The function 'GrTextXY' is  provided for compatibility  with
  1060.           the  original 256 color DJGPP graphics library. It draws the text
  1061.           using the 16  row BIOS font on VGA-s or the  14 row font on EGA-s
  1062.           in the standard direction unmagnified.
  1063.  
  1064.           void    GrTextXY(int x,int y,char *text,int fg,int bg);
  1065.  
  1066.                The size  of a font,  a character  or a text  string can  be
  1067.           obtained  by  calling  one  of  the  following  functions.  These
  1068.           functions also take into consideration the magnification and text
  1069.           direction specified in the text option structure passed to them.
  1070.  
  1071.           int     GrFontHeight(GrTextOption *opt);
  1072.                  int     GrFontWidth(GrTextOption *opt);
  1073.                  int     GrCharWidth(int chr,GrTextOption *opt);
  1074.                  int     GrCharHeight(int chr,GrTextOption *opt);
  1075.                  int     GrStringWidth(char *text,int length,GrTextOption *opt);
  1076.                  int     GrStringHeight(char *text,int length,GrTextOption *opt);
  1077.  
  1078.                The  'GrTextRegion' structure  and its  associated functions
  1079.           can be used to implement a fast (as much as  possible in graphics
  1080.           modes)  rectangular text window using a  fixed font. Clipping for
  1081.           such  windows is  done in  character  size increments  instead of
  1082.           pixels  (i.e. no partial characters  are drawn). Only fixed fonts
  1083.           can  be used in their  natural size. 'GrDumpText'  will cache the
  1084.           code of  the drawn  characters in the  buffer pointed  to by  the
  1085.           'backup' slot  (if it is non-NULL) and will draw a character only
  1086.           if  the previously  drawn  character  in  that  grid  element  is
  1087.           different.  This can  speed  up text  scrolling significantly  in
  1088.           graphics modes. The supported text types are the same as above.
  1089.  
  1090.           typedef struct {
  1091.                      GrFont *txr_font;                   /* font to be used */
  1092.                      char   *txr_buffer;                 /* pointer to text buffer */
  1093.                      char   *txr_backup;                 /* optional backup buffer */
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.                  LIBGRX graphics library user's manual                                                       20
  1100.  
  1101.  
  1102.               int     txr_xpos;                   /* upper left corner X coordinate */
  1103.                      int     txr_ypos;                   /* upper left corner Y coordinate */
  1104.                      int     txr_width;                  /* width of area in chars */
  1105.                      int     txr_height;                 /* height of area in chars */
  1106.                      int     txr_lineoffset;             /* offset in buffer(s) between lines */
  1107.                      union {
  1108.                          int v;                          /* color when no attributes */
  1109.                          GrColorTableP p;                /* ptr to color table otherwise */
  1110.                      } txr_fgcolor,txr_bgcolor;          /* foreground, background */
  1111.                      char    txr_chrtype;                /* character type (see above) */
  1112.                  } GrTextRegion;
  1113.  
  1114.                  void    GrDumpChar(int chr,int col,int row,GrTextRegion *r);
  1115.                  void    GrDumpText(int col,int row,int wdt,int hgt,GrTextRegion *r);
  1116.                  void    GrDumpTextRegion(GrTextRegion *r);
  1117.  
  1118.           The 'GrDumpTextRegion'  function outputs  the whole text  region,
  1119.           while  'GrDumpText'  draws  only  a user-specified  part  of  it.
  1120.           'GrDumpChar' updates the character in the buffer at the specified
  1121.           location with the new character passed to it as argument and then
  1122.           draws the new character on the screen as well. 
  1123.  
  1124.  
  1125.           Drawing in user coordinates
  1126.  
  1127.                There  is a  second  set of  the  graphics primitives  which
  1128.           operates  in user coordinates. Every context has a user to screen
  1129.           coordinate mapping  associated with it. An  application specifies
  1130.           the user window by calling the 'GrSetUserWindow' function.
  1131.  
  1132.           void    GrSetUserWindow(int x1,int y1,int x2,int y2);
  1133.  
  1134.           A  call to  this  function  it  in  fact  specifies  the  virtual
  1135.           coordinate limits  which will be mapped onto  the current context
  1136.           regardless of the size of the context. For example, the call:
  1137.  
  1138.           GrSetUserWindow(0,0,11999,8999);
  1139.  
  1140.           tells the  library  that the  program  will perform  its  drawing
  1141.           operations in a coordinate system X:0...11999 (width = 12000) and
  1142.           Y:0...8999 (height = 9000). This  coordinate range will be mapped
  1143.           onto  the  total  area  of  the  current   context.  The  virtual
  1144.           coordinate system can also be shifted. For example:
  1145.  
  1146.           GrSetUserWindow(5000,2000,16999,10999);
  1147.  
  1148.           The  user coordinates  can  event  be  used  to  turn  the  usual
  1149.           left-handed coordinate system (0:0  corresponds to the upper left
  1150.           corner) to a right handed one (0:0 corresponds to the bottom left
  1151.           corner) by calling:
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.                  LIBGRX graphics library user's manual                                                       21
  1158.  
  1159.  
  1160.           GrSetUserWindow(0,8999,11999,0);
  1161.  
  1162.                The library  also provides  three utility functions  for the
  1163.           query of the  current user coordinate  limits and for  converting
  1164.           user coordinates to screen coordinates and vice versa.
  1165.  
  1166.           void    GrGetUserWindow(int *x1,int *y1,int *x2,int *y2);
  1167.                  void    GrGetScreenCoord(int *x,int *y);
  1168.                  void    GrGetUserCoord(int *x,int *y);
  1169.  
  1170.                If an application  wants to  take advantage of  the user  to
  1171.           screen coordinate  mapping  it has  to  use the  user  coordinate
  1172.           version  of the graphics primitives.  These have exactly the same
  1173.           parameter   passing  conventions   as  their   screen  coordinate
  1174.           counterparts. NOTE: the user coordinate system is not initialized
  1175.           by  the library!  The application  has to  set up  its coordinate
  1176.           mapping  before  calling  any   of  the  use  coordinate  drawing
  1177.           functions -- otherwise the program will almost certainly exit (in
  1178.           a  quite ungraceful fashion) with a 'division by zero' error. The
  1179.           list of supported user coordinate drawing functions:
  1180.  
  1181.           void    GrUsrPlot(int x,int y,int c);
  1182.                  void    GrUsrLine(int x1,int y1,int x2,int y2,int c);
  1183.                  void    GrUsrHLine(int x1,int x2,int y,int c);
  1184.                  void    GrUsrVLine(int x,int y1,int y2,int c);
  1185.                  void    GrUsrBox(int x1,int y1,int x2,int y2,int c);
  1186.                  void    GrUsrFilledBox(int x1,int y1,int x2,int y2,int c);
  1187.                  void    GrUsrFramedBox(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
  1188.                  void    GrUsrCircle(int xc,int yc,int r,int c);
  1189.                  void    GrUsrEllipse(int xc,int yc,int xa,int ya,int c);
  1190.                  void    GrUsrCircleArc(int xc,int yc,int r,int start,int end,int c);
  1191.                  void    GrUsrEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  1192.                  void    GrUsrFilledCircle(int xc,int yc,int r,int c);
  1193.                  void    GrUsrFilledEllipse(int xc,int yc,int xa,int ya,int c);
  1194.                  void    GrUsrFilledCircleArc(int xc,int yc,int r,int start,int end,int c);
  1195.                  void    GrUsrFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  1196.                  void    GrUsrPolyLine(int numpts,int points[][2],int c);
  1197.                  void    GrUsrPolygon(int numpts,int points[][2],int c);
  1198.                  void    GrUsrFilledPolygon(int numpts,int points[][2],int c);
  1199.                  int     GrUsrPixel(int x,int y);
  1200.  
  1201.                  void    GrUsrCustomLine(int x1,int y1,int x2,int y2,GrLineOption *o);
  1202.                  void    GrUsrCustomBox(int x1,int y1,int x2,int y2,GrLineOption *o);
  1203.                  void    GrUsrCustomCircle(int xc,int yc,int r,GrLineOption *o);
  1204.                  void    GrUsrCustomEllipse(int xc,int yc,int xa,int ya,GrLineOption *o);
  1205.                  void    GrUsrCustomCircleArc(int xc,int yc,int r,int start,int end,GrLineOption *o);
  1206.                  void    GrUsrCustomEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLineOption *o);
  1207.                  void    GrUsrCustomPolyLine(int numpts,int points[][2],GrLineOption *o);
  1208.                  void    GrUsrCustomPolygon(int numpts,int points[][2],GrLineOption *o);
  1209.  
  1210.                  void    GrUsrPatternedPlot(int x,int y,GrPattern *p);
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.                  LIBGRX graphics library user's manual                                                       22
  1217.  
  1218.  
  1219.           void    GrUsrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  1220.                  void    GrUsrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  1221.                  void    GrUsrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp);
  1222.                  void    GrUsrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp);
  1223.                  void    GrUsrPatternedCircleArc(int xc,int yc,int r,int start,int end,GrLinePattern *lp);
  1224.                  void    GrUsrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLinePattern *lp);
  1225.                  void    GrUsrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp);
  1226.                  void    GrUsrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp);
  1227.  
  1228.                  void    GrUsrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p);
  1229.                  void    GrUsrPatternFilledCircle(int xc,int yc,int r,GrPattern *p);
  1230.                  void    GrUsrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p);
  1231.                  void    GrUsrPatternFilledCircleArc(int xc,int yc,int r,int start,int end,GrPattern *p);
  1232.                  void    GrUsrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrPattern *p);
  1233.                  void    GrUsrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p);
  1234.  
  1235.                  GrTextOption *GrUsrFindBestFont(int width,int height,int magnify,char *family,GrTextOption *where);
  1236.                  void    GrUsrDrawChar(int chr,int x,int y,GrTextOption *opt);
  1237.                  void    GrUsrDrawString(char *text,int length,int x,int y,GrTextOption *opt);
  1238.                  void    GrUsrTextXY(int x,int y,char *text,int fg,int bg);
  1239.  
  1240.  
  1241.           Graphics cursors
  1242.  
  1243.                The library  provides support for the creation  and usage of
  1244.           an unlimited number of  graphics cursors. An application can  use
  1245.           these  cursors for any purpose. Cursors always save the area they
  1246.           occupy before they are  drawn. When moved or erased  they restore
  1247.           this  area. As  a general  rule of  thumb, an  application should
  1248.           erase  a cursor before making changes  to an area it occupies and
  1249.           redraw the  cursor after  finishing the  drawing. All cursor  and
  1250.           mouse  related declaration  are in  the include  file "mousex.h".
  1251.           Cursors are created with the 'GrBuildCursor' function:
  1252.  
  1253.           GrCursor *GrBuildCursor(char *data,int w,int h,int xo,int yo,GrColorTableP c);
  1254.  
  1255.           The 'data', 'w' (=width),  'h' (=height) and 'c' (=  color table)
  1256.           arguments are  similar to the  arguments of  the pixmap  building
  1257.           library function: 'GrBuildPixmap'. (See that paragraph for a more
  1258.           detailed  explanation.) The  only difference  is that  the pixmap
  1259.           data is  interpreted slightly  differently: any pixel  with value
  1260.           zero  is taken as a "transparent" pixel, i.e. the background will
  1261.           show through the cursor pattern at that pixel. A pixmap data byte
  1262.           with value = 1 will refer to the first color in the table, and so
  1263.           on. The 'xo' (= X offset) and 'yo' (= Y offset) arguments specify
  1264.           the position (from the top left corner of the cursor pattern)  of
  1265.           the cursor's "hot point". The 'GrCursor' data structure:
  1266.  
  1267.           typedef struct {
  1268.                      GrVidRAM  cr_andmask;               /* cursor bitmap to AND */
  1269.                      GrVidRAM  cr_ormask;                /* cursor bitmap to OR */
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.                  LIBGRX graphics library user's manual                                                       23
  1276.  
  1277.  
  1278.               GrVidRAM  cr_work;                  /* work area */
  1279.                      GrVidRAM  cr_save;                  /* screen save area */
  1280.                      int   cr_xcord,cr_ycord;            /* cursor position on screen */
  1281.                      int   cr_xsize,cr_ysize;            /* cursor size */
  1282.                      int   cr_xoffs,cr_yoffs;            /* LU corner to hot point offset */
  1283.                      int   cr_xwork,cr_ywork;            /* save/work area sizes */
  1284.                      int   cr_xwpos,cr_ywpos;            /* save/work area position on screen */
  1285.                      int   cr_displayed;                 /* set if displayed */
  1286.                  } GrCursor;
  1287.  
  1288.           is typically not used  (i.e. read or changed) by  the application
  1289.           program,  it should just pass pointers to these structures to the
  1290.           appropriate   library   functions.   Other  cursor   manipulation
  1291.           functions:
  1292.  
  1293.           void GrDestroyCursor(GrCursor *cursor);
  1294.                  void GrDisplayCursor(GrCursor *cursor);
  1295.                  void GrEraseCursor(GrCursor *cursor);
  1296.                  void GrMoveCursor(GrCursor *cursor,int x,int y);
  1297.  
  1298.  
  1299.           Mouse event handling
  1300.  
  1301.                All  mouse  services need  the presence  of  a mouse  and an
  1302.           installed  Microsoft compatible mouse  driver. An application can
  1303.           test whether a mouse is available by calling the function:
  1304.  
  1305.           int  MouseDetect(void);
  1306.  
  1307.           which will return zero if no mouse (or mouse  driver) is present,
  1308.           non-zero  otherwise. If the mouse  is present the application may
  1309.           decide if it wants to use the mouse in interrupt-driven or polled
  1310.           mode.  The polled mode  is compatible  with previous  releases of
  1311.           DJGPP  and  the 256  color graphics  library,  it uses  the mouse
  1312.           driver interrupts (INT 33h) to query the mouse about its position
  1313.           and buttons. This  method is adequate  if the program can  do the
  1314.           polling  in  a tight  enough loop.  If  the program  does lengthy
  1315.           computations in the background during which a "frozen"  mouse and
  1316.           the loss  of mouse button presses  would be disturbing it  has to
  1317.           use  the interrupt driven method.  For this a  patched version of
  1318.           GO32 is needed -- a GO32  version dated after the middle of April
  1319.           1992 should work. The interrupt driven mouse event mechanism uses
  1320.           an event  queue library (described in  the document "EVENTS.DOC")
  1321.           which  stores  all user  interaction  events  (mouse presses  and
  1322.           keyboard  hits)  in  a  queue,   timestamped,  in  the  order  of
  1323.           occurrence. The disadvantage of the interrupt-driven  mouse event
  1324.           mechanism is that  it may be  harder to debug. To  select between
  1325.           the two modes the following function needs to be called:
  1326.  
  1327.           void MouseEventMode(int use_interrupts);
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.           LIBGRX graphics library user's manual                                24
  1334.  
  1335.  
  1336.           If the 'use_interrupts' parameter  is zero the mouse is  put into
  1337.           polled  mode  (this  is  the  default),  otherwise  it will  work
  1338.           interrupt-driven.  After selecting  the  mode, the  mouse can  be
  1339.           initialized by calling:
  1340.  
  1341.           void MouseInit(void);
  1342.  
  1343.           It is not  necessary to call this function as  the first call the
  1344.           'MouseGetEvent'  (see  later)  function  will  also  perform  the
  1345.           initialization. However, if the mouse event mode is changed after
  1346.           using 'MouseGetEvent', a call  to 'MouseInit' is the only  way to
  1347.           enforce the change. 
  1348.  
  1349.                If the mouse is used in interrupt-driven mode, it is  a good
  1350.           practice to  call 'MouseUnInit' before exiting  the program. This
  1351.           will restore any interrupt vectors hooked by the program to their
  1352.           original values.
  1353.  
  1354.           void MouseUnInit(void);
  1355.  
  1356.           The mouse can be controlled with the following functions:
  1357.  
  1358.           void MouseSetSpeed(int speed);
  1359.                  void MouseSetAccel(int thresh,int accel);
  1360.                  void MouseSetLimits(int x1,int y1,int x2,int y2);
  1361.                  void MouseGetLimits(int *x1,int *y1,int *x2,int *y2);
  1362.                  void MouseWarp(int x,int y);
  1363.  
  1364.           The library  calculates the mouse  position only  from the  mouse
  1365.           mickey  counters. (To avoid the  limit and 'rounding  to the next
  1366.           multiple  of eight' problem with  the Microsoft mouse driver when
  1367.           it finds  itself in a graphics  mode unknown to  it.) The 'speed'
  1368.           parameter to the 'MouseSetSpeed' function  is used as a  divisor,
  1369.           i.e.  coordinate  changes are  obtained  by  dividing the  mickey
  1370.           counter changes  by this value. In high resolution graphics modes
  1371.           the  value  of  one just  works  fine,  in  low resolution  modes
  1372.           (320x200 or  similar) it is best  set the speed to  two or three.
  1373.           (Of  course, it also depends  on the sensitivity  the mouse.) The
  1374.           'MouseSetAccel' function is used to control the ballistic effect:
  1375.           if  a mouse coordinate changes between two samplings by more than
  1376.           the 'thresh' parameter,  the change is multiplied  by the 'accel'
  1377.           parameter. NOTE: some mouse  drivers perform similar calculations
  1378.           before  reporting the  coordinates in mickeys.  In this  case the
  1379.           acceleration  done by the library  will be additional  to the one
  1380.           already  performed by the mouse  driver. The limits  of the mouse
  1381.           movement can be set (passed limits will be clipped to the screen)
  1382.           with  'MouseSetLimits'  (default is  the  whole  screen) and  the
  1383.           current limits can be obtained with 'MouseGetLimits'. 'MouseWarp'
  1384.           sets the mouse cursor to the specified position.
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.           LIBGRX graphics library user's manual                                25
  1391.  
  1392.  
  1393.                As  typical  mouse drivers  do not  know  how to  draw mouse
  1394.           cursors in  high resolution graphics  modes, the mouse  cursor is
  1395.           drawn by the library. The mouse cursor can be set with:
  1396.  
  1397.           void MouseSetCursor(GrCursor *cursor);
  1398.                  void MouseSetColors(int fg,int bg);
  1399.  
  1400.           'MouseSetColors' uses  an internal arrow pattern,  the color 'fg'
  1401.           will be used as  the interior of it and 'bg'  will be the border.
  1402.           The current mouse cursor can be obtained with:
  1403.  
  1404.           GrCursor *MouseGetCursor(void);
  1405.  
  1406.           The mouse cursor can be displayed/erased with:
  1407.  
  1408.           void MouseDisplayCursor(void);
  1409.                  void MouseEraseCursor(void);
  1410.  
  1411.           The mouse cursor can be left  permanently displayed. All graphics
  1412.           primitives except  for the  few non-clipping functions  check for
  1413.           conflicts with the mouse  cursor and erase it before  the drawing
  1414.           if necessary. Of course,  it may be more  efficient to erase  the
  1415.           cursor  manually before  a long  drawing sequence  and redraw  it
  1416.           after  completion. The  library provides  an alternative  pair of
  1417.           calls for this  purpose which will  erase the cursor  only if  it
  1418.           interferes with the drawing:
  1419.  
  1420.           int  MouseBlock(GrContext *c,int x1,int y1,int x2,int y2);
  1421.                  void MouseUnBlock(void);
  1422.  
  1423.           'MouseBlock' should be  passed the context  in which the  drawing
  1424.           will take  place and  the limits  of the affected  area. It  will
  1425.           erase the cursor only  if it interferes with  the drawing. If  it
  1426.           returns  a non-zero value then 'MouseUnBlock' has to be called at
  1427.           the end of the drawing, otherwise it should not be called.
  1428.  
  1429.                The  library  supports (beside  the  simple  cursor drawing)
  1430.           three types  of "rubberband" attached  to the  mouse cursor.  The
  1431.           'MouseSetCursorMode'  function  is  used  to  select  the  cursor
  1432.           drawing mode.
  1433.  
  1434.           void MouseSetCursorMode(int mode,...);
  1435.  
  1436.           The parameter 'mode' can have the following values:
  1437.  
  1438.           /*
  1439.                   * MOUSE CURSOR modes:
  1440.                   *  M_CUR_NORMAL -- just the cursor
  1441.                   *  M_CUR_RUBBER -- rectangular rubber band (XOR-d to the screen)
  1442.                   *  M_CUR_LINE   -- line attached to the cursor
  1443.                   *  M_CUR_BOX    -- rectangular box dragged by the cursor
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.                  LIBGRX graphics library user's manual                                                       26
  1450.  
  1451.  
  1452.            */
  1453.                  #define M_CUR_NORMAL    0
  1454.                  #define M_CUR_RUBBER    1
  1455.                  #define M_CUR_LINE      2
  1456.                  #define M_CUR_BOX       3
  1457.  
  1458.           'MouseCursorMode'  takes  different parameters  depending  on the
  1459.           cursor drawing mode selected. The accepted call formats are:
  1460.  
  1461.           MouseSetCursorMode(M_CUR_NORMAL);
  1462.                  MouseSetCursorMode(M_CUR_RUBBER,xanchor,yanchor,color);
  1463.                  MouseSetCursorMode(M_CUR_LINE,xanchor,yanchor,color);
  1464.                  MouseSetCursorMode(M_CUR_BOX,dx1,dy1,dx2,dy2,color);
  1465.  
  1466.           The  anchor parameters  for the  rubberband and  rubberline modes
  1467.           specify a fixed  screen location to which the other corner of the
  1468.           primitive is bound. The 'dx1' through 'dy2' parameters define the
  1469.           offsets of the  corners of the dragged  box from the hotpoint  of
  1470.           the mouse cursor. The color value passed is always  XOR-ed to the
  1471.           screen.  I.e. if an application wants the rubberband to appear in
  1472.           a given color on a  given background then it has to pass  the XOR
  1473.           of these two colors to 'MouseSetCursorMode'.
  1474.  
  1475.           The  status  of the  mouse cursor  can  be obtained  with calling
  1476.           'MouseCursorIsDisplayed'. This function  will return non-zero  if
  1477.           the cursor is displayed, zero if it is erased.
  1478.  
  1479.           int  MouseCursorIsDisplayed(void);
  1480.  
  1481.                The  'MouseGetEvent' function  is  used to  obtain the  next
  1482.           mouse  or keyboard  event.  It takes  a  flag with  various  bits
  1483.           encoding the  type of  event needed.  It returns the  event in  a
  1484.           'MouseEvent'   structure.   The   relevant    declarations   from
  1485.           "mousex.h":
  1486.  
  1487.           void MouseGetEvent(int flags,MouseEvent *event);
  1488.  
  1489.                  typedef struct {
  1490.                      int  flags;                         /* flags (see above) */
  1491.                      int  x,y;                           /* coordinates */
  1492.                      int  buttons;                       /* button state */
  1493.                      int  key;                           /* key code from keyboard */
  1494.                      int  kbstat;                        /* keybd status (ALT, CTRL, etc..) */
  1495.                      long time;                          /* time stamp of the event */
  1496.                  } MouseEvent;
  1497.  
  1498.           The event structure has been extended with a keyboard status word
  1499.           (thus  a  program  can  check  for  combinations  like  ALT-<left
  1500.           mousebutton  press>) and a time  stamp (in DOS  clock ticks since
  1501.           the start of  the program) which can be used  to check for double
  1502.           clicks,  etc...  The  following   macros  have  been  defined  in
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.           LIBGRX graphics library user's manual                                27
  1509.  
  1510.  
  1511.           "mousex.h"   to   help  in   creating   the   control  flag   for
  1512.           'MouseGetEvent' anddecoding the variousbits inthe eventstructure:
  1513.  
  1514.           /*
  1515.                   * MOUSE event flag bits
  1516.                   */
  1517.                  #define M_MOTION        0x001
  1518.                  #define M_LEFT_DOWN     0x002
  1519.                  #define M_LEFT_UP       0x004
  1520.                  #define M_RIGHT_DOWN    0x008
  1521.                  #define M_RIGHT_UP      0x010
  1522.                  #define M_MIDDLE_DOWN   0x020
  1523.                  #define M_MIDDLE_UP     0x040
  1524.                  #define M_BUTTON_DOWN   (M_LEFT_DOWN | M_MIDDLE_DOWN | M_RIGHT_DOWN)
  1525.                  #define M_BUTTON_UP     (M_LEFT_UP   | M_MIDDLE_UP   | M_RIGHT_UP)
  1526.                  #define M_BUTTON_CHANGE (M_BUTTON_UP | M_BUTTON_DOWN )
  1527.  
  1528.                  /*
  1529.                   * MOUSE button status bits
  1530.                   */
  1531.                  #define M_LEFT          1
  1532.                  #define M_RIGHT         2
  1533.                  #define M_MIDDLE        4
  1534.  
  1535.                  /*
  1536.                   * Other bits and combinations
  1537.                   */
  1538.                  #define M_KEYPRESS      0x080           /* keypress */
  1539.                  #define M_POLL          0x100           /* do not wait for the event */
  1540.                  #define M_NOPAINT       0x200
  1541.                  #define M_EVENT         (M_MOTION | M_KEYPRESS | M_BUTTON_DOWN | M_BUTTON_UP)
  1542.  
  1543.                  /*
  1544.                   * KEYBOARD status word bits
  1545.                   */
  1546.                  #define KB_RIGHTSHIFT   0x01            /* right shift key depressed */
  1547.                  #define KB_LEFTSHIFT    0x02            /* left shift key depressed */
  1548.                  #define KB_CTRL         0x04            /* CTRL depressed */
  1549.                  #define KB_ALT          0x08            /* ALT depressed */
  1550.                  #define KB_SCROLLOCK    0x10            /* SCROLL LOCK active */
  1551.                  #define KB_NUMLOCK      0x20            /* NUM LOCK active */
  1552.                  #define KB_CAPSLOCK     0x40            /* CAPS LOCK active */
  1553.                  #define KB_INSERT       0x80            /* INSERT state active */
  1554.  
  1555.                  #define KB_SHIFT        (KB_LEFTSHIFT | KB_RIGHTSHIFT)
  1556.  
  1557.           'MouseGetEvent'  will   display  the  mouse  cursor   if  it  was
  1558.           previously  erased and the 'M_NOPAINT' bit is not set in the flag
  1559.           passed to it. In this case it will also erase the cursor  when an
  1560.           event has been obtained.
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.           LIBGRX graphics library user's manual                                28
  1567.  
  1568.  
  1569.           NOTE: some of  the mouse  event constants  have different  values
  1570.           than  in the  original  DJGPP graphics  library. This  change was
  1571.           necessary  to  better follow  the  mouse  driver conventions  for
  1572.           assigning bits with similar functions.
  1573.  
  1574.           The generation of mouse and  keyboard events can be  individually
  1575.           enabled or disabled (by passing a non-zero or zero, respectively,
  1576.           value in the corresponding 'enable_XX' parameter) by calling:
  1577.  
  1578.           void MouseEventEnable(int enable_kb,int enable_ms);